#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START kmod-native
# depends: xz-native
# Useful for creating an initramfs for the bootable image

save_CFLAGS="$CFLAGS"
save_CPPFLAGS="$CPPFLAGS"
save_LDFLAGS="$LDFLAGS"
export CFLAGS='-O2 -g'
export CPPFLAGS="-I${xtools}${build_prefix}/include"
export LDFLAGS="-L${xtools}${build_prefix}/lib"
export PKG_CONFIG_SYSROOT_DIR="${xtools}${build_prefix}"
export PKG_CONFIG_LIBDIR="${xtools}${build_prefix}/lib/pkgconfig"

reset_mtime kmod kmod/configure.ac
rm -rf build/kmod-native
mkdir -p build/kmod-native
cd build/kmod-native
env \
	LIBLZMA_LIBS="-llzma" \
../../kmod/configure \
	--host="$BUILD" \
	--build="$BUILD" \
	--prefix="$build_prefix" \
	--enable-static \
	--disable-shared \
	--with-xz \
	${AUTOCRAP_KLUDGE}

cd ../..
make_native_build build/kmod-native
for tool in depmod modinfo; do
	ln -sf kmod "${xtools}${build_prefix}/bin/$tool"
done

export CFLAGS="$save_CFLAGS"
export CPPFLAGS="$save_CPPFLAGS"
export LDFLAGS="$save_LDFLAGS"
unset PKG_CONFIG_LIBDIR
unset PKG_CONFIG_SYSROOT_DIR

# RECIPE END kmod-native
